#include <pthread.h>
#include <iostream>
#include <unistd.h>
#include <vector>

const int num = 10;

void *routine(void *args)
{
    sleep(1);
    printf("args的地址: %p\n", args);
    std::string name = static_cast<const char*>(args);
    //delete (char*) args;

    std::cout << "new线程名字：" << name << std::endl;
    sleep(1);
    return nullptr;
}


int main()
{
    
    std::vector<pthread_t> tids;
    for(int i = 0; i < num; i++)
    {
        pthread_t tid;
        //char *id = new char[64];
        char id[64];
        snprintf(id, 64, "thread-%d", i);
        printf("id的地址: %p\n", id);
        int n = pthread_create(&tid, nullptr, routine, id);
        if (n == 0)
        {
            tids.push_back(tid);
        }
        else
            continue;
    }
    for(int i = 0; i < num; i++)
    {
        int n = pthread_join(tids[i], nullptr);
        if(n == 0)
        {
            std::cout << "等待进程成功" << std::endl;
        }
    }
    return 0;
}